package com.scau.meetingbook.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.scau.meetingbook.service.EmployeesService;
import com.scau.meetingbook.pojo.Employees;
import com.scau.meetingbook.vo.ResultVO;

import java.util.List;

@RestController
@RequestMapping("/employees")
public class EmployeesController {

    @Autowired
    private EmployeesService employeesService;

    @PostMapping("/insertEmployees")
    public ResultVO insertEmployees( Employees employees) throws Exception {
        return employeesService.insertEmployees(employees);
    }

    @GetMapping("/getEmployeesById")
    public ResultVO<Employees> getEmployeesById(Integer id) throws Exception {
        return employeesService.getEmployeesById(id);
    }

    @PutMapping("/updateEmployeesById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "employee_id", value = "员工ID", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "name", value = "姓名", required = false, dataType = "String"),
            @ApiImplicitParam(name = "login_password", value = "登录密码（MD5加密加随机盐值）", required = false, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "员工状态：active（活跃）、frozen（冻结）、pending（待审核）", required = false, dataType = "String"),
            @ApiImplicitParam(name = "create_by", value = "创建人", required = false, dataType = "Integer")
    })
    public ResultVO updateEmployeesById(@ApiParam  (value = "员工对象") Employees employees) throws Exception {
        return employeesService.updateEmployeesById(employees);
    }

    @DeleteMapping("/deleteEmployeesById")
    public ResultVO deleteEmployeesById(Integer id) throws Exception {
        return employeesService.deleteEmployeesById(id);
    }

    @PostMapping("/login")
    public ResultVO login(@RequestBody Employees employees) throws Exception {
        return employeesService.login(employees);
    }

    @PostMapping("/register")
    public ResultVO register(@RequestBody Employees employees) throws Exception {
        return employeesService.register(employees);
    }

    @PostMapping("/changeEmployeeStatus")
    public ResultVO chanceEmployeeStatus(Integer id, String status) throws Exception {
        return employeesService.changeEmployeeStatus(id, status);
    }
    @GetMapping("/getEmployees")
    public ResultVO<Page<Employees>> getEmployees(Integer pageNum, Integer pageSize){
        return employeesService.getAllEmployees(pageNum, pageSize);
    }

}